package com.qf.realms;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

/**
 * IntelliJ IDEA -> shiro1125
 * 2019/11/25 21:15
 *
 * @author zmyao
 * 别看，我是渣渣。
 */
public class RealmA  extends AuthorizingRealm {
//处理授权的操作
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }
//处理认证代码
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {

        String  username = (String)token.getPrincipal();
        char[] password =  (char[]) token.getCredentials();

        String pwd = new String(password);
        if (username.equals("admin") && pwd.equals("123")){
            return  new SimpleAuthenticationInfo(username,pwd,"myrealm");
        }
        return null;
    }
}
